home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7780 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: anvil.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: timimng an event in milli seconds.
  5. Date: 27 Feb 1996 07:21:17 -0800
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4gv7hdINNb8v@anvil.ugrad.cs.ubc.ca>
  8. References: <Pine.SUN.3.91.960218173348.23890B-100000@aloha.cc.columbia.edu>
  9. NNTP-Posting-Host: anvil.ugrad.cs.ubc.ca
  10.  
  11. In article <Pine.SUN.3.91.960218173348.23890B-100000@aloha.cc.columbia.edu>,
  12. Gopal V. Sarikela <gvs3@columbia.edu> wrote:
  13. >
  14. >Hello everyone, 
  15. >    This might be a repeat question but i am sorry for asking.
  16. >I have access to Borland 4.0 compiler on DOS and Windows for IBM and gcc 
  17. >and cc for UNIX.
  18. >
  19. >    I am intersested in measuring time taken by an event like a key 
  20. >hit or the user typing something.
  21. >
  22. >    On the Borland compiler, the command int86(int, *REGS, *REGS) and 
  23. >ti_hund gives the time in hundreth of a second, thats how we can time an 
  24. >event.
  25. >
  26. >    I am interested in _milli seconds_ can anybody help me? I am also 
  27. >intersted in doing the same on the unix workstations at the university .
  28.  
  29. There is a _standard_ function called clock(), you know... it gives a time in
  30. clock ticks, which you can divide by the clock tick period, given by
  31. CLOCKS_PER_SECOND. Don't forget to #include <time.h>.
  32.  
  33. BTW, I think that this is normally measured in virtual process time, not real
  34. time. I doubt that you can get a more accurate timer without referring to
  35. something like gettimeofday(), which is a UNIX thing, not a standard function.
  36. gettimeofday() gives you a struct timeval, which contains seconds and
  37. milliseconds.
  38.  
  39. I know that it is available on PC's, since the requestor side of a
  40. communication protocol of mine was recently ported to Windows/Winsock, and this
  41. code uses gettimeofday() to measure round-trip times.
  42. -- 
  43.  
  44.